<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 要求以数组的形式返回字符串参数所有排列组合
    const _permute = string => {
      // 补全代码
      const stringArray = string.split('')
      let a = []
      Object.assign(a, stringArray)   //浅拷贝

      for (let index = 0; index < stringArray.length; index++) {
        let arry = []
        let item = a.splice(index, 1)  //删除项
        function fn(a) {  //[a,b,c]
          for (let j = 0; j < a.length; j++) {
            arry.push(item + a[j])
          }
          console.log('-------a-----')
          console.log(a)
          console.log('------arry----')
          console.log(arry)

          let b = []
          Object.assign(b, a)
          for (let k = 0; k < arry.length; k++) {
            for (let i = 0; i < a.length; i++) {
              console.log(arry[k])   //ab
              if (arry[k].includes(a[i])) {
                a.splice(i, 1)
              }
              console.log('------a  a  --------')
              console.log(a)
            }
            for (let j = 0; j < a.length; j++) {
              arry[k] = arry[k] + a[j]
            }
            Object.assign(a, b)
            console.log('------arry  arry----')
            console.log(arry)
          }

          


          // fn(a)
          // if (a.length === 1) {
          //   return
          // }


        }

        fn(a)



        Object.assign(a, stringArray)
      }


    }

    _permute('abc')

  </script>
</body>

</html>